<html>

<script type="text/javascript">

function doc(iframe) {
    return iframe.contentWindow.document || iframe.ownerDocument;
}

onload=function() {
    if (Math.random() > 0.5) {
      top();
    } else {
      right();
    }
}

function top() {
    topAd = doc(document.getElementById("test")).getElementsByTagName("iframe")[1];
    n = Math.floor(Math.random() * 4 + 1);
    ad = topAd.getElementById("ad" + n);
    y = getY(topAd) + getY(ad);
    x = 10 + Math.random() * 100;
    setPosition(x, y);
}

function right() {
    rightAd = doc(document.getElementById("test")).getElementsByTagName("iframe")[0]; 
    test = rightAd.contentWindow.document.getElementById("test");
    y = getY(test) + getY(rightAd);
    height = test.offsetHeight;

    n = select();
}

function setPosition() {
    window.name = x + " " + y;
}

function getY(oElement) {
    var iReturnValue = 0;
    while( oElement != null ) {
    iReturnValue += oElement.offsetTop;
        oElement = oElement.offsetParent;
    }
    return iReturnValue;
}

function select(probability) {
    var total = 0;
    for(var p in probability) {
        total += probability[p];
    }
    var r = Math.floor(Math.random() * total);

    var n = 0;
    for(var p in probability) {
        n += probability[p];
        if (r < n) {
            return p;
        }
    }
    return 0;
}

</script>

<body>

<iframe frameborder="0" marginwidth="0" marginheight="0" scrolling="no" style="visibility: visible; height: 1300px; " width="100%" name="test" id="test" src="cse.html"></iframe>

</body>

</html>
